package com.cch.cooperation.api.bookkeepping.service;


import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cch.cooperation.dao.bookkeeping.mapper.BookkeepingCategoryMapper;
import com.cch.cooperation.dao.bookkeeping.model.BookkeepingCategory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 记账服务实现类
 *
 * @author cch
 */
@Service
public class BookkeepingCategoryServiceImpl {

    @Resource
    private BookkeepingCategoryMapper mapper;

    public List<BookkeepingCategory> queryList(Integer type) {
        LambdaQueryWrapper<BookkeepingCategory> query = new LambdaQueryWrapper<>();
        query.eq(Objects.nonNull(type), BookkeepingCategory::getType, type);
        return mapper.selectList(query);
    }

    public Map<String, BookkeepingCategory> getMapByIds(List<String> ids) {
        if (CollUtil.isEmpty(ids)) {
            return new HashMap<>();
        }
        return mapper.selectBatchIds(ids).stream().collect(Collectors.toMap(BookkeepingCategory::getId, o -> o, (o1, o2) -> o1));
    }

}
